﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using TorchView.SharedStashEditor.Models;
using TorchView.GameContent.Units;
using TorchView.GameContent.Affixes;

namespace TorchView.SharedStashEditor.Helpers
{
    public class ItemEffectConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return null;

            string name = (string)value;
            Item itemRef = ItemCollection.DefaultCollection[name];
            List<Game.Effect> gameEffects = new List<Game.Effect>();

            foreach (Effect itemEffect in itemRef.Effects)
            {
                Game.Effect gameEffect = itemEffect.CreateGameEffect();
                gameEffects.Add(gameEffect);
            }
            foreach (string affixName in itemRef.Affixes)
            {
                Affix affix = AffixItemList.DefaultList[affixName];
                if (affix != null)
                {
                    foreach (Effect affixEffect in affix.Effects)
                    {
                        Game.Effect gameEffect = affixEffect.CreateGameEffect();
                        gameEffects.Add(gameEffect);
                    }
                }
            }

            return gameEffects;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
